package com.lib.model.answer;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.lib.model.dto.InformationDto;

public class AdminInfoDao extends SqlMapClientDaoSupport implements IAdminInfoDao {

	@Override
	public ArrayList<InformationDto> getInfoList(int startPage, int startBlock) 
	{	
		ArrayList<InformationDto> list = new ArrayList<InformationDto>();
		Map<String, Object> map = new HashMap<String, Object>();
				map.put("startpage", startPage);
				map.put("endpage", startBlock);
				list = (ArrayList<InformationDto>)getSqlMapClientTemplate().queryForList("getInfoList",map);
			return list;
	}

	@Override
	public int SearchCount() {
		int count=0;
			count = (Integer) getSqlMapClientTemplate().queryForObject("countRecord");
		return count;
	}

	@Override
	public InformationDto getInfoDetail(int informationNum) {
		InformationDto bdto = new InformationDto();
		
				try{
					bdto = (InformationDto)getSqlMapClientTemplate().queryForObject("getinfoDetail",informationNum);
					getSqlMapClientTemplate().update("infoCount",informationNum);
				}catch (Exception e) {
				}
		return bdto;
	}

	@Override
	public boolean updateInfoDetail(InformationDto udto) {
		int count=0;
		
		try {
			getSqlMapClientTemplate().update("updateInfoDetail", udto);
			count=1;
		} catch (Exception e) {
			count=-1;
		}
		return count>0?true:false;
	}

	@Override
	public boolean deleteBoard(int informationNum) {
		int count=0;
		
			try {
				getSqlMapClientTemplate().delete("deleteInfo", informationNum);
				count=1;
			} catch (Exception e) {
				count=-1;
			}
		return count>0?true:false;
	}

	@Override
	public boolean writeInfo(InformationDto dto) {
		int count=0;
		//System.out.println(dto.getId());
		try {
			getSqlMapClientTemplate().insert("writeInfo",dto);
			System.out.println(dto.toString());
			count=1;
		} catch (Exception e) {
		}
		System.out.println(count);
		return count>0?true:false;
	}

	@Override
	public ArrayList<InformationDto> homeInfo() {
		// TODO Auto-generated method stub
		return (ArrayList<InformationDto>)getSqlMapClientTemplate().queryForList("homeInfo");
	}
}
